package cn.leedsoft.and.crimeintent.common;

import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.support.v4.app.Fragment;
import android.widget.Toast;
import cn.leedsoft.and.crimeintent.controller.photo_gallery.PollService;

/**
 * Created by leeds on 2016/9/5 10:58.
 */
public class VisibleFragment extends Fragment {
    private BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            Toast.makeText(getActivity(), "Got a broadcast intent : " + intent.getAction(), Toast.LENGTH_SHORT).show();
            mBroadcastReceiver.setResultCode(Activity.RESULT_CANCELED);//取消通知信息
        }
    };

    @Override
    public void onResume() {
        super.onResume();
        IntentFilter intentFilter = new IntentFilter(PollService.ACTION_SHOW_NOTIFICATION);
        getActivity().registerReceiver(mBroadcastReceiver, intentFilter, PollService.CUSTOM_PRIVATE, null);// dynamic register broadcast receiver
    }

    @Override
    public void onPause() {
        super.onPause();
        getActivity().unregisterReceiver(mBroadcastReceiver);//unregister
    }
}
